package com.jobs.project.controller;

import com.alibaba.fastjson2.JSONObject;
import com.jobs.project.components.HttpClientUtils;
import com.jobs.project.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author 王博
 * @DateTime 2024-05-24 15:30
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private HttpClientUtils httpClientUtils;
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/forGet")
    public String forGet() {
        Map<String,String>  params = new HashMap<>();
        params.put("name","zhangsan");
        params.put("address","河南");
        System.out.println(Thread.currentThread().getId());
        ResponseEntity<User> user = restTemplate.getForEntity("http://localhost:8181/user/getUser", User.class);
        return JSONObject.toJSONString(user);
    }

    @GetMapping("/getUser")
    public User getUser(){
        System.out.println(Thread.currentThread().getId());
        User user = new User();
        user.setAge(10);
        user.setName("张三");
        user.setId(1L);
        throw new RuntimeException("ss");
    }


}
